﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-26-21:10
//  * @Description:
//  */

using System.Collections.Generic;
using Code.DataManager;
using Code.GameLogic.BaseClass;
using QFramework;
using UnityEngine;
using UnityEngine.UI;

namespace Code.GameLogic.XianJian.UI
{
    public class XianJianListUI:AbsGameLogicUI
    {
        private Dictionary<string, XianJianUIBo> _XianJianBos;
        private GameObject _mainCanvas;
        private GameObject _XianJianList;
        
        public override void LoadManagerData()
        {
            _XianJianBos = this.GetModel<SettingBo>().XianJianUIList;
            _mainCanvas = GameObject.Find("MainCanvas");
        }


        public override void CreateGameObj()
        {
            CreateXianJianListUI();
            CreatePlaceMouseIcon();
        }

        private void CreatePlaceMouseIcon()
        {
            if (_mainCanvas.transform != null)
            {
                GameObject mouseIcon = new GameObject("PlaceMouseIcon");
                mouseIcon.transform.parent = _mainCanvas.transform.parent.transform;
                mouseIcon.AddComponent<XianJianMouseIconUI>();
            }
        }

        private void CreateXianJianListUI()
        {
            GameObject xianJianListPrefab = (GameObject)Resources.Load("UI/仙剑/仙剑UIList");
            GameObject xianJianUIPrefab = (GameObject)Resources.Load("UI/仙剑/仙剑UI");
            _XianJianList = Instantiate(xianJianListPrefab, _mainCanvas.transform);
            foreach (var item in _XianJianBos)
            {
                var xianJianBo = item.Value;
                GameObject xianJianUI = Instantiate(xianJianUIPrefab, _XianJianList.transform);
                Image image = xianJianUI.transform.Find("icon").gameObject.GetComponent<Image>();
                image.sprite = Resources.Load<Sprite>("防御塔/" + xianJianBo.BaseDescription.TypeName);
                XianJianUIController xianJianUIController = xianJianUI.AddComponent<XianJianUIController>();
                xianJianUIController.XianJianUI = xianJianBo;
            }
        }
    }
}